import type {RouteRecordRaw} from 'vue-router'
import {readonly, watch} from 'vue'

/**
 * 菜单类型（meta.type），需要显示为菜单导航的路由需要此字段：
 * 1-菜单
 * 2-页面组件
 * 3-接口
 * 4-仅结构（用于页面呈现树状结构，方便管理上下级关系，不参与任何权限管理，此类型的记录只含有name即可）
 * 5-外部链接
 */

/**
 * 菜单全路径（meta.fullPath），需要显示为菜单导航的路由需要此字段且值唯一
 */

// 初始菜单，值不要修改比如push新元素
export const initialMenus = readonly<RouteRecordRaw[]>([
	{
		path: 'dashboard',
		name: 'Dashboard',
		component: () => import('@/views/dashboard/dashboard.vue'),
		meta: {
			type: 1,
			fullPath: '/dashboard',
			title: 'route.dashboard',
			icon: 'el-icon-HomeFilled',
			keepAlive: true,
			affix: true
		}
	},
	{
		path: 'profile',
		name: 'Profile',
		component: () => import('@/views/profile/index.vue'),
		meta: {
			type: 1,
			fullPath: '/profile',
			title: 'route.profile',
			icon: 'el-icon-UserFilled',
			keepAlive: true,
			hidden: true
		}
	}
])

export const homeRoute: RouteRecordRaw = {
	path: '/',
	name: 'Home',
	redirect: '/dashboard',
	component: () => import('@/layouts/index.vue'),
	meta: {
		title: 'route.ToDashboard',
		hidden: true
	},
	children: <RouteRecordRaw[]>initialMenus
}

watch(() => homeRoute.children, () => {
	console.warn('请勿修改 homeRoute.children 的值，如果想添加路由，请使用router.addRoute()')
}, {
	deep: true
})

export const staticRoutes: RouteRecordRaw[] = [
	homeRoute,
	{
		path: '/login',
		name: 'Login',
		component: () => import('@/views/login/login.vue'),
		meta: {
			title: 'route.login',
			hidden: true
		}
	},
	{
		path: '/modifyPassword',
		name: 'ModifyPassword',
		component: () => import('@/views/modifyPassword/modifyPassword.vue'),
		meta: {
			title: 'route.modifyPassword',
			hidden: true
		}
	},
	{
		path: '/forgetPassword',
		name: 'ForgetPassword',
		component: () => import('@/views/forgetPassword/forgetPassword.vue'),
		meta: {
			title: 'route.forgetPassword',
			hidden: true
		}
	},
	{
		path: '/activateEmail',
		name: 'ActivateEmail',
		component: () => import('@/views/userEmail/activateEmail.vue'),
		meta: {
			title: 'route.activeMailBox',
			hidden: true
		}
	},
	{
		path: '/401',
		name: 'Page401',
		component: () => import('@/views/error-page/401.vue'),
		meta: {
			title: 'route.page401',
			hidden: true
		}
	},
	{
		path: '/404',
		name: 'Page404',
		component: () => import('@/views/error-page/404.vue'),
		meta: {
			title: 'route.page404',
			hidden: true
		}
	},
	/**
	 * vue-router 4.0+ 的版本中，会自动计算每个路由的得分，从而匹配得分最高的路由，与路由声明的顺序无关
	 * 总的来说，声明越精确的路由得分越高，越模糊的得分越低
	 * 匹配404
	 */
	{
		path: '/:pathMatch(.*)',
		name: 'RedirectTo404',
		redirect: '/404',
		meta: {
			title: 'route.ToPage404',
			hidden: true
		}
	}
]
